<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>pressure-insert</title>
</head>
<!-- css js -->
<link rel="stylesheet" href="../css/css1.css" type="text/css" />
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/myValidate.js"></script>
<script type="text/javascript">
<!--
function validateLowAndHigh() {
	var low = document.getElementById('insertForm:low').value;	
	var high = document.getElementById('insertForm:high').value;
	if(isNumber(low) && isNumber(high)) {
		return true;
	}
	alert('low and high must be number!');
	return false;
}

function validateRemarks() {
	var remarks = document.getElementById('insertForm:remarks').value;
	var length = fucCheckLength2(remarks);
	if(length > 512) {
		alert('remarks should be less than 512');
		return false;
	}
	return true;
}

function check() {
	if(validateLowAndHigh() && validateRemarks()) {
		document.getElementById('insertForm:insert2').click();
	}
}
-->  
</script>

<body>
<f:view>
<a4j:form id="insertForm">

	<!-- 新增"pressure" table -->
	<table id="insertTable" >
		<tr>
			<td><h:outputText value="low"/></td>
			<td><h:inputText id="low" size="6" value="#{BloodPressureManagedBean.pressure.low }" maxlength="3"/></td>
			<td><h:outputText value="high"/></td>
			<td><h:inputText id="high" size="6" value="#{BloodPressureManagedBean.pressure.high }" maxlength="3"/></td>
		</tr>
		<tr>
			<td><h:outputText value="remarks"/></td>
			<td colspan="3"><h:inputTextarea id="remarks" value="#{BloodPressureManagedBean.pressure.remarks }" cols="40" rows="4"></h:inputTextarea></td>
		</tr>
		<tr>
			<a4j:commandButton id="insert1" value="insert" styleClass="btn"
							   onclick="check();">
			</a4j:commandButton>
			<a4j:commandButton id="insert2" value="insert" 
							   style="display:none"
							   action="#{BloodPressureManagedBean.insert }"
							   oncomplete="returnResult();"
							   reRender="insertForm:insertFlag">
			</a4j:commandButton>
		</tr>
	</table>
	<!-- alert user : is this "pressure" insert succeed! -->
	<h:inputHidden id="insertFlag" value="#{BloodPressureManagedBean.insertFlag }"></h:inputHidden>		
</a4j:form>
</f:view>
</body>
<script type="text/javascript">
<!--
		function returnResult() {
			var insertFlag = document.getElementById('insertForm:insertFlag').value;
			if(insertFlag == '1') {
				alert('insert succeed!');
			} else {
				alert('insert fail!');
			}
			//parent.location.reload();
			window.opener.location.href = window.opener.location.href; 
			window.close();
		}
-->	 		
</script>
</html>